package yto.freemarker.java8.lambda;

import org.junit.Test;
import yto.freemarker.java8.lambda.Iinterface.MyFun;

import java.util.Comparator;
import java.util.function.Consumer;

/**
 * Lambda表达式的基础语法
 *
 * @author dongxing
 * @create 2018-06-13 23:19
 **/
public class TestLambda01 {

    @Test
    public void test1() {
        int num = 100;

        Runnable runnable = () -> {
            System.out.println("hello world!你好，世界！" + num);
        };

        runnable.run();

    }

    @Test
    public void test2() {
        Consumer<String> consumer = (e) -> {
            System.out.println(e);
        };

        consumer.accept("实现的接口！");
    }

    @Test
    public void test3() {
        Comparator<Integer> comparator = (x, y) -> Integer.compare(x, y);

        comparator.compare(1, 2);
    }

    /**
     * 需求：
     * 对一个数进行运算
     */
    @Test
    public void test4() {

        Integer operation = operation(100, (num) -> num*num);
        System.out.println(operation);

    }

    private Integer operation(Integer num, MyFun myFun) {
        return myFun.getValue(num);
    }


}
